package com.study.service.impl;

import com.study.mapper.DeptMapper;
import com.study.pojo.Dept;
import com.study.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


/**
 * 类名称：部门服务层实现类
 * 描述：dept service impl
 *
 * @author: Lixx
 * 创建时间: 2025/03/03
 */

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    /**
     * 查找全部
     *
     * @return {@link List }<{@link Dept }>
     * @author Lixx
     * @date 2025/03/04
     */
    @Override
    public List<Dept> findAll() {
        List<Dept> list =  deptMapper.findAll();
        return list;
    }

    /**
     * 删除部门
     *
     * @param id 编号
     * @author Lixx
     * @date 2025/03/04
     */
    @Override
    public void deleteDept(Integer id) {
        deptMapper.deleteDept(id);
    }

    /**
     * 添加部门
     *
     * @param dept 部门
     * @author Lixx
     * @date 2025/03/04
     */
    @Override
    public void addDept(Dept dept) {
        //TODO 补全属性信息，createTime,updateTime
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());

        //TODO 调用mapper
        deptMapper.addDept(dept);
    }

    /**
     * 按 ID 查找
     *
     * @param id 编号
     * @return
     * @author Lixx
     * @date 2025/03/05
     */
    @Override
    public Dept findById(Integer id) {
        Dept dept = deptMapper.findById(id);
        return dept;
    }

    /**
     * 更新部门
     *
     * @param dept 部门对象
     * @author Lixx
     * @date 2025/03/05
     */

    @Override
    public void updateDept(Dept dept) {
        //TODO 补全属性信息，updateTime
        dept.setUpdateTime(LocalDateTime.now());

        //TODO 调用mapper
        deptMapper.updateDept(dept);
    }
}
